<template>
	<!-- 地址管理 -->
	<view class="address">
		<view style="width: 100%; height:100%;" v-if="addressArr.length==0">
			<none></none>
		</view>
		<view v-else class="address-content">
			<view class="addressInfo" v-for="(item,index) in addressArr" :key="index" @tap="updateAddress(item.id)">
				<view class="info">
					<view class="info-detail">
						<view class="address-userinfo">
							<view v-if="item.is_default=='1'" class="default">默认</view>
							<view class="info-title">下单用户:{{item.consignee}},{{item.consignee_phone}}</view>
						</view>
						<view class="homeAddress">上门地址：{{item.location}}{{item.detail}}</view>
					</view>
				</view>
				<view class="edit" @click.stop="inAddSite(index,item)">编辑</view>
			</view>
		</view>
		<!-- 新增地址按钮 -->
		<view class="addAddress" @tap="inAddSite(-1,'addSite')">新增收货地址</view>
	</view>
</template>

<script>
	import util from '@/component/commen/api/util.js';
	import none from "@/otherPages/none/none.vue"
	export default {
		components:{
			none
		},
		onShow() {
			this.getAddress()
		},
		data() {
			return {
				addressArr:[]
			};
		},
		mounted() {
			
		},
		methods:{
			getAddress(){//获取默认地址数据
				// ?i=2&t=0&v=2.7.4&from=wxapp&c=entry&a=wxapp&do=address&m=wjyk_recycle&sign=af6fa483102e7451f094e335cf3ab466&uid=2
				var params = {
					do:"address",
					uid:uni.getStorageSync("uid")
				}
				util.requestWithSign(params).then(res=>{
					console.log("获取地址：",res)
					this.addressArr = res.data
				})
			},
			inAddSite(index,item){//点击进入新增/修改地址页面
				uni.navigateTo({
					url:`/otherPages/siteAddOrModify/siteAddOrModify?id=${index}&detailId=${item.id}`
				})
			},
			updateAddress(id){//点击修改默认地址
				console.log(id)
				var params = {
					do:"address",
					op:"setDefault",
					id:id,
					uid:uni.getStorageSync("uid")
				}
				util.requestWithSign(params).then(res=>{
					console.log("选择地址返回",res)
					uni.showToast({
						title:res.message,
						icon:"none"
					})
					uni.navigateBack()
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.address{
	font-size: 29rpx;
	.address-content{
		padding: 20rpx;
		padding-bottom: 0;
		box-sizing: border-box;
		background: #fff;
		.addressInfo{
			padding-bottom: 20rpx;
			margin-top: 10rpx;
			border-bottom: #e5e5e5 2rpx solid;
			display: flex;
			.info{
				padding: 20rpx;
				// border: 1px solid #f00;
				width: 85%;
				.info-detail{
					.address-userinfo{
						// border: 1px solid #f00;
						display: flex;
						align-items: center;
						.default{
							margin-right: 10rpx;
							border: 2rpx solid #00b388;
							padding: 4rpx 18rpx;
							font-size: 26rpx;
							font-weight: bold;
							color: #00b388;
							border-radius: 10rpx;
						}
						.info-title{
							font-weight: bold;
							font-size: 27rpx;
							white-space: nowrap; /* 文本不换行 */
							overflow: hidden; /* 溢出部分隐藏 */
							text-overflow: ellipsis; /* 文本溢出时显示省略号 */
						}
					}
					.homeAddress{
						margin: 20rpx 0;
						font-size: 25rpx;
						color: #9c9c9c;
					}
				}
			}
			.edit{
				width: 120rpx;
				height: 50rpx;
				line-height: 50rpx;
				border-radius: 10rpx;
				font-size: 26rpx;
				color: #969696;
				margin-top: 20rpx;
				text-align: center;
				background: #dddddd;
			}
		}
	}
	// 新增收获地址按钮
	.addAddress{
		position: fixed;
		bottom: 0;
		width: 100%;
		text-align: center;
		color: #fff;
		font-size: 28.5rpx;
		padding: 20rpx 0;
		background: #00b388;
	}
}
</style>
